import {Injectable, TemplateRef} from '@angular/core';
import {getClassName} from 'codelyzer/util/utils';

@Injectable({
  providedIn: 'root'
})
export class ToastService {
  toasts: any[] = [];
  constructor() { }
  show(textOrTpl: string | TemplateRef<any>, options: any = {}) {
    this.toasts.push({ textOrTpl, ...options });
  }

  remove(toast) {
    this.toasts = this.toasts.filter(t => t !== toast);
  }

  showinfo(msg:string){
    this.show(msg,{
      classname:'bg-success text-light',
      delay:2000,
      autohide: true,
      headertext:'消息提示',
      ariaLive:'alert'
    });
  }

  showWarning(msg:string){
    this.show(msg,  {
      classname:'bg-warning text-light',
      delay:3000,
      autohide: true,
      headertext:'警告消息',
      ariaLive:'alert'
    });
  }

  showError(msg:string){
    this.show(msg,  {
      classname:'bg-danger text-light',
      delay:3000,
      autohide: true,
      headertext:'错误消息',
      ariaLive:'alert'
    });
  }
}
